package com.jzsk.variable.center.zhengxin.base.configures;

import com.jzsk.variable.center.zhengxin.base.interceptor.LogInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author jiangli
 */
@Configuration
public class WebAppConfigure implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LogInterceptor())
                .addPathPatterns("/**");
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")  //允许跨域访问的路径
                .allowedOrigins("*")    //允许访问的源
                .allowedMethods("POST", "GET", "PUT", "DELETE", "OPTIONS")   //允许的请求方式
                .maxAge(3600)   //允许的检测间隔时间
                .allowedHeaders("*")    //允许的请求头
                .allowCredentials(true);    //允许发送cookie
    }
}
